var mySwiper = new Swiper ('.swiper',{
    autoplay:true,
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    loop : true,
    pagination: {
        el: '.swiper-pagination',
        clickable :true,
      },
}) 


// API分类
//获取元素
let li=document.querySelectorAll('#classificationUl li')


//需求:当鼠标移入li时,     当鼠标移出时
// 改变背景色为:#1271ef    背景色为白色
// 图片改为-c路径          图片变回原本路径 

// 遍历
li.forEach(function(dom,i){
    dom.addEventListener('mouseover',function(){
        // console.log(123);
        this.style.backgroundColor='#1271ef'
        this.querySelector('img').src=`../imgs/api0${i+1}-c.svg`
    })

    dom.addEventListener('mouseout',function(){
        // console.log(456);
        this.style.backgroundColor='white'
        this.querySelector('img').src=`../imgs/api0${i+1}.svg`
    })
})



//需求:移入business-list,停止计时器
    // 移出business-list,开始计时器

//计时器
//获取元素
let businessList=document.querySelectorAll('.business-list')
let businessNr=document.querySelector('.business-nr')
// console.log(businessList);
//定义变量
let index=0;

let timeId=setInterval(paoMa,2000)

function paoMa(){
    // 移出激活样式
    businessList[index].classList.remove('active')
        
    //自增1
    ++index;

    //判断
    if(index===businessList.length) index=0;

    // 添加激活样式
    businessList[index].classList.add('active')
}

businessNr.addEventListener('mouseover',function(){
    // console.log(123);
    clearInterval(timeId)
})
businessNr.addEventListener('mouseout',function(){
    // console.log(456);
    timeId=setInterval(paoMa,2000)
})


// 需求:当滚动条滚动大于500时,显示回到顶部按钮,否则隐藏

//获取元素
let topBtn=document.querySelector('.top-btn')

window.addEventListener('scroll',function(){
    // console.log(window);

    //获取滚动条距离
    let distance=document.documentElement.scrollTop

    //判断
    if(distance>=500){
        topBtn.style.display='block'
    }else{
        topBtn.style.display='none'
    }
})

//需求:移入topBtn时,显示高亮,移出恢复
topBtn.addEventListener('mouseover',function(){
    topBtn.style.backgroundPositionY='-40px'
})
topBtn.addEventListener('mouseout',function(){
    topBtn.style.backgroundPositionY=''
})



//需求:点击topBtn,丝滑回到顶部

topBtn.addEventListener('click',function(){
    // console.log(123);
    // window.scrollTo(0,0)
    window.scrollTo({
        top:0,
        behavior:"smooth"
    })

})



